package models
{
	import events.DaTinEvent;
	
	import flash.utils.setTimeout;
	
	import mx.core.Application;

	public class DaTinUploadData
	{
		private static var _data:DaTinUploadData;
		/**
			 * 图片缩略图宽高
			 */
		public static const PIC_MIN_WIDTH:int=80;
		public static const PIC_MIN_HEIGHT:int=60;
		/**
		 * 图片与上传ITEM的间隔
		 */
		public static const PIC_GAP:int=4;
		/**
		 * 上传ITEM的进度条高度
		 */
		public static const UPLOAD_LOADING_HEIGHT:int=16;
		/**
		 * 删除按钮高度
		 */
		public static const UPLOAD_DELETE_BUTTON_HEIGHT:int=20;
		/**
		 * 上传ITEM宽高
		 */
		public static const UPLOAD_ITEM_HEIGHT:int=PIC_GAP * 3 + PIC_MIN_HEIGHT + UPLOAD_LOADING_HEIGHT + UPLOAD_DELETE_BUTTON_HEIGHT;
		public static const UPLOAD_ITEM_WIDTH:int=PIC_GAP * 2 + PIC_MIN_WIDTH;
		/**
		* 最大同时上传图片数量
		*/
		public static const MAX_LOADING_NUM:int=3;
		/**
		 * 单个session最大上传照片数量600
		 */
		public static const MAX_SESSION_UPLOAD_COUNT:int=600;
		public static const SUCCESS:String="success";
		public static const FAIL:String="fail";
		public static const UPLOAD_SERLET_URL:String="myfileupload";
		public static const GETPIC_SERVLET_URL:String="GetPic";
		public static const REMOVE_TEMP:String = "RemoveTemp";
		public static const CREATE_TEMP_SPACE:String = "CreateTempOrderSpace";
		public static const GET_EDIT_INFO = "GetTempImg";

		/**
		 * 图片列表
		 */
		private var picItemArray:Array=[];

		/**
		 * 当前总共正在上传数量
		 */
		private var currentLoadingNum:int;
 
		/**
		 * 上传使用的seesionId
		 */
		private var _sessionId:String;
		private var _productTypeId:String;
		private var _productId:String;

		/**
		 * 成功、失败、剩余数量
		 */
		private var _successCount:int;
		private var _failCount:int;
		private var _leftCount:int;
	
		
		public function DaTinUploadData()
		{
			if (_data)
				return;
			//初始化获取上传照片的最小打印宽高
			var allParameters:Object=Application.application.parameters;
			if (allParameters)
			{
 				_sessionId=String(allParameters["sessionId"]);
				_productId=String(allParameters["productId"]);
				_productTypeId=String(allParameters["productTypeId"]);
			}
		}

		/**
		 * 修改正在上传照片的数量
		 */
		public function changeLoadingNum(isAdd:Boolean=true):void
		{
			if (isAdd && currentLoadingNum < MAX_LOADING_NUM)
			{
				currentLoadingNum++;
			}
			else if (!isAdd && currentLoadingNum > 0)
			{
				currentLoadingNum--;
			}
		}

		public function set uploadCount(obj:Object):void
		{
			_successCount=obj.success;
			_failCount=obj.fail;
			_leftCount=obj.left;
			var evt:DaTinEvent=new DaTinEvent(DaTinEvent.CHANGE_ITEMS_COUNT);
			evt.data=obj;
			setTimeout(evt.dispatch, 0);
		}

		public function get successCount():int
		{
			return _successCount;
		}

		public function get leftCount():int
		{
			return _leftCount;
		}

		public function get loadingNum():int
		{
			return currentLoadingNum;
		}

		public static function getInstance():DaTinUploadData
		{
			if (_data == null)
				_data=new DaTinUploadData();
			return _data;
		}
  
		public function set successCount(value:int):void
		{
			_successCount=value;
		}

		public function set failCount(value:int):void
		{
			_failCount=value;
		}

		public function set leftCount(value:int):void
		{
			_leftCount=value;
		}
		
		public function set sessionId(sessionId:String):void{
			_sessionId=sessionId;
		}

		public function get sessionId():String
		{
			return _sessionId;
		}
		
		public function get productId():String{
			return _productId;
		}
		
		public function get productTypeId():String{
			return _productTypeId;
		}

	}
}